﻿package com.mui.controls
{
    import __AS3__.vec.*;
    import com.greensock.*;
    import com.mui.utils.*;
    import flash.display.*;
    import flash.events.*;
    import flash.text.*;

    public class Alert extends Object
    {
        public static const YES:int = 1;
        public static const NO:int = 2;
        public static const OK:int = 4;
        public static const CANCEL:int = 8;
        public static const CLOSE:int = 16;
        public static const Mode_Blur:String = "blur";
        public static const Mode_None:String = "none";
        public static const Mode_NoneNotModal:String = "nonenotmodal";
        public static const Mode_Simple:String = "simple";
        public static var text:String = "";
        public static var title:Object;
        public static var buttonFlags:uint = 0;
        public static var parent:DisplayObjectContainer;
        public static var okLabel:String = "确定";
        public static var calcelLabel:String = "取消";
        public static var yesLabel:String = "是";
        public static var noLabel:String = "否";
        public static var checkBoxLabel:String = "今日不再提示！";
        public static var okLabelDefault:String = "确定";
        public static var calcelLabelDefault:String = "取消";
        public static var yesLabelDefault:String = "是";
        public static var noLabelDefault:String = "否";
        public static var checkBoxLabelDefault:String = "今日不再提示！";
        public static var closeHandler:Function;
        public static var iconClass:Class;
        public static var defaultButtonFlag:uint = 4;
        public static var buttonWidth:int = 49;
        public static var buttonHeight:int = 25;
        public static var buttonGap:int = 25;
        public static var showCloseBtn:Boolean;
        public static var isWiggle:Boolean;
        public static var isFlowMouse:Boolean;
        public static var wordWrap:Boolean = true;
        public static var textColor:uint = 16777215;
        public static var titleColor:uint = 16777215;
        public static var buttonColor:uint = 5143985;
        public static var buttonTextColor:uint = 16777215;
        public static var backgroundColor:uint = 5143985;
        public static var backgroundAlpha:Number = 0;
        public static var buttonStyleName:String;
        public static var titleTextFormat:TextFormat;
        public static var messageTextFormat:TextFormat;
        public static var mode:String = "simple";
        public static var alertWinRenderer:Class = null;
        public static var timerOut:int = 0;
        public static var timerNO:Boolean = false;
        public static var extendObj:Object;
        private static var _defaultAlertWinRenderer:Class = null;
        private static var stage:Object = null;
        private static var _instance:Alert;
        public static var alertWinList:Vector.<GAlertWin> = new Vector.<GAlertWin>;

        public function Alert(param1:DisplayObjectContainer)
        {
            if (_instance != null)
            {
                throw new Error(" AlertManager 单例 ");
            }
            setStage(param1);
            return;
        }// end function

        public static function get defaultAlertWinRenderer() : Class
        {
            return _defaultAlertWinRenderer;
        }// end function

        public static function set defaultAlertWinRenderer(param1:Class) : void
        {
            alertWinRenderer = param1;
            _defaultAlertWinRenderer = param1;
            return;
        }// end function

        public static function init(param1:DisplayObjectContainer) : void
        {
            if (_instance == null)
            {
                _instance = new Alert(param1);
            }
            return;
        }// end function

        public static function setStage(param1:DisplayObjectContainer) : void
        {
            stage = param1;
            return;
        }// end function

        public static function removeAllAlertWin() : void
        {
            var _loc_1:GAlertWin = null;
            for each (_loc_1 in alertWinList)
            {
                
                _loc_1.parent.removeChild(_loc_1);
            }
            alertWinList.length = 0;
            return;
        }// end function

        public static function show(param1:String = "", param2 = null, param3:uint = 4, param4:Sprite = null, param5:Function = null, param6:Class = null, param7:uint = 4) : Sprite
        {
            var myAlert:Sprite;
            var container:DisplayObjectContainer;
            var containerWidth:Number;
            var containerHeight:Number;
            var clickHandler:Function;
            var removeHandler:Function;
            var text:* = param1;
            var title:* = param2;
            var flags:* = param3;
            var parent:* = param4;
            var closeHandler:* = param5;
            var iconClass:* = param6;
            var defaultButtonFlag:* = param7;
            clickHandler = function (event:MouseEvent) : void
            {
                var _loc_2:* = event.target as DisplayObject;
                var _loc_3:* = event.currentTarget as GAlertWin;
                if (_loc_3.window != null && !_loc_3.window.contains(_loc_2))
                {
                    if (_loc_3.promptBackground)
                    {
                        flick(_loc_3.promptBackground);
                    }
                }
                return;
            }// end function
            ;
            removeHandler = function (event:Event) : void
            {
                myAlert.removeEventListener(Event.REMOVED_FROM_STAGE, removeHandler);
                myAlert.removeEventListener(MouseEvent.CLICK, clickHandler);
                alertWinList.splice(alertWinList.indexOf(myAlert), 1);
                return;
            }// end function
            ;
            Alert.text = text;
            Alert.title = title;
            Alert.buttonFlags = flags;
            if (parent)
            {
                Alert.parent = parent;
            }
            Alert.closeHandler = closeHandler;
            if (iconClass)
            {
                Alert.iconClass = iconClass;
            }
            Alert.defaultButtonFlag = defaultButtonFlag;
            if (!stage && !parent)
            {
                throw new Error("AlertManager尚未初始化!必需指定Alert窗口显示的容器");
            }
            if (parent)
            {
                containerWidth = parent.width;
                containerHeight = parent.height;
                container = parent;
            }
            else
            {
                if (stage is Stage)
                {
                    containerWidth = stage.stageWidth;
                    containerHeight = stage.stageHeight;
                }
                else if (stage is DisplayObjectContainer)
                {
                    containerWidth = stage.stage.stageWidth;
                    containerHeight = stage.stage.stageHeight;
                }
                container = stage;
            }
            if (alertWinRenderer)
            {
                myAlert = gGAlertWin(alertWinRenderer, containerWidth, containerHeight);
            }
            else
            {
                myAlert = new GAlertWin(stage.stageWidth, stage.stageHeight);
            }
            alertWinList.push(myAlert);
            container.addChild(myAlert);
            if (myAlert is GAlertWin)
            {
                myAlert.addEventListener(MouseEvent.CLICK, clickHandler);
                myAlert.addEventListener(Event.REMOVED_FROM_STAGE, removeHandler);
            }
            if (isWiggle)
            {
                wiggle(myAlert);
            }
            resetToDefault();
            return myAlert;
        }// end function

        public static function gGAlertWin(param1:Class, param2:Number, param3:Number) : GAlertWin
        {
            var _loc_4:* = UICompomentPool.getUICompoment(param1, param2, param3) as GAlertWin;
            _loc_4.stageWidth = param2;
            _loc_4.height = param3;
            return _loc_4;
        }// end function

        public static function flick(param1:DisplayObject) : void
        {
            var timeLite:TimelineMax;
            var obj:* = param1;
            var x:* = obj.x;
            var y:* = obj.y;
            timeLite = new TimelineMax();
            timeLite.append(new TweenMax(obj, 0.05, {frameInterval:1, glowFilter:{color:14540253, alpha:0.5, blurX:100, blurY:100, inner:true}}));
            timeLite.append(new TweenMax(obj, 0.05, {frameInterval:1, glowFilter:{color:14540253, alpha:1, blurX:1, blurY:1, inner:true}}));
            timeLite.append(new TweenMax(obj, 0.05, {frameInterval:1, glowFilter:{color:14540253, alpha:0.5, blurX:100, blurY:100, inner:true}}));
            timeLite.append(new TweenMax(obj, 0.05, {frameInterval:1, glowFilter:{color:14540253, alpha:1, blurX:1, blurY:1, inner:true}}));
            timeLite.append(new TweenMax(obj, 0.05, {frameInterval:1, glowFilter:{color:14540253, alpha:0.5, blurX:100, blurY:100, inner:true}}));
            timeLite.append(new TweenMax(obj, 0.05, {frameInterval:1, glowFilter:{color:14540253, alpha:1, blurX:1, blurY:1, inner:true}, onComplete:function () : void
            {
                timeLite.stop();
                timeLite.kill();
                timeLite = null;
                return;
            }// end function
            }));
            timeLite.play();
            return;
        }// end function

        public static function wiggle(param1:DisplayObject) : void
        {
            var timeLite:TimelineLite;
            var obj:* = param1;
            var x:* = obj.x;
            var y:* = obj.y;
            timeLite = new TimelineLite();
            timeLite.append(new TweenLite(obj, 0.02, {x:x - 7, y:y}));
            timeLite.append(new TweenLite(obj, 0.02, {x:x, y:y + 5}));
            timeLite.append(new TweenLite(obj, 0.02, {x:x + 7, y:y}));
            timeLite.append(new TweenLite(obj, 0.02, {x:x, y:y - 5}));
            timeLite.append(new TweenLite(obj, 0.02, {x:x - 7, y:y}));
            timeLite.append(new TweenLite(obj, 0.02, {x:x, y:y + 5}));
            timeLite.append(new TweenLite(obj, 0.02, {x:x + 7, y:y}));
            timeLite.append(new TweenLite(obj, 0.02, {x:x, y:y - 5}));
            timeLite.append(new TweenLite(obj, 0.02, {x:x - 7, y:y}));
            timeLite.append(new TweenLite(obj, 0.02, {x:x, y:y + 5}));
            timeLite.append(new TweenLite(obj, 0.02, {x:x + 7, y:y}));
            timeLite.append(new TweenLite(obj, 0.02, {x:x, y:y - 5}));
            timeLite.append(new TweenLite(obj, 0.02, {x:x, y:y, onComplete:function () : void
            {
                timeLite.stop();
                timeLite.kill();
                timeLite = null;
                return;
            }// end function
            }));
            timeLite.play();
            return;
        }// end function

        public static function resetToDefault() : void
        {
            okLabel = okLabelDefault;
            calcelLabel = calcelLabelDefault;
            yesLabel = yesLabelDefault;
            noLabel = noLabelDefault;
            text = "";
            title = null;
            buttonFlags = 0;
            parent = null;
            closeHandler = null;
            iconClass = null;
            defaultButtonFlag = 4;
            buttonWidth = 49;
            buttonHeight = 25;
            buttonGap = 25;
            textColor = 16777215;
            titleColor = 16777215;
            buttonColor = 5143985;
            buttonTextColor = 16777215;
            backgroundColor = 5143985;
            backgroundAlpha = 0;
            titleTextFormat = null;
            messageTextFormat = null;
            alertWinRenderer = defaultAlertWinRenderer;
            mode = "simple";
            timerOut = 0;
            buttonStyleName = null;
            wordWrap = true;
            showCloseBtn = false;
            isWiggle = false;
            isFlowMouse = false;
            timerNO = false;
            extendObj = null;
            checkBoxLabel = checkBoxLabelDefault;
            return;
        }// end function

    }
}
